package edu.gatech.bsbmule.view;

import java.awt.Font;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import org.jfree.data.xy.XYDataset;

import edu.gatech.bsbmule.util.StatisticsManager;
import edu.gatech.bsbmule.util.XYDatasetAdapter;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 * Creates panel to display "end of game" screen
 * 
 * @version 1.0 11/18/13
 * @author Hanjie
 */
public class EndOfGameScreen extends JPanel {
	
	private static EndOfGameScreen instance;
	
	public static EndOfGameScreen getInstance() {
		if (instance == null) {
			instance = new EndOfGameScreen();
		}
		return instance;
	}
	
	private EndOfGameScreen() {
		
		setLayout(new GridLayout(3, 1, 10, 30));
		
		JLabel lblGameEnds = new JLabel("Game Ends!");
		lblGameEnds.setFont(new Font("Tahoma", Font.PLAIN, 36));
		lblGameEnds.setHorizontalAlignment(SwingConstants.CENTER);
		add(lblGameEnds);
		
		JButton btnExit = new JButton("Exit");
		btnExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);
			}
		});
		btnExit.setFont(new Font("Tahoma", Font.PLAIN, 24));
		add(btnExit);
		
		JButton btnStats = new JButton("See statistics");
		btnStats.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				XYDataset dataset = XYDatasetAdapter.getDatasetFromTable(StatisticsManager.getInstance().getTable());
				MainWindow.getInstance().setPanel(new StatisticsScreen(dataset));
			}
		});
		btnStats.setFont(new Font("Tahoma", Font.PLAIN, 24));
		add(btnStats);

	}

}
